import Axios, { downLoadFile } from '@/utils/request';

/* ***********  计算因子  *********** */

/**
 * 左侧树点击查询
 * @param code
 */
export function getFactorListByPs(code: string): Promise<any> {
    return Axios.get('/original/factor/listByps/' + code);
}

/**
 * 查询原始范围/计算因子是否使用中，是否可禁用
 */
export function checkBoundOrFactorIsUsed(type: string | number, data: any): Promise<any> {
    return Axios.post('/original/list/isUsed/' + type, data);
}

/**
 * 启用、禁用计算因子
 */
export function updateFactorStatus(data): Promise<any> {
    return Axios.post('/original/update/factor', data);
}

/**
 * 删除计算因子
 */
export function deleteFactor(data): Promise<any> {
    return Axios.post('/original/factor/delete', data);
}

/**
 * 导出计算因子 pdf格式
 */
export function exportFactorToPDF(data) {
    return downLoadFile({
        url: '/original/export/factor/pdf',
        method: 'post',
        data: data,
        loading: true,
        loadingMsg: '正在准备导出，请稍后··· ···',
    });
}

/**
 * 导出计算因子 json格式
 */
export function exportFactorToJson(data) {
    return downLoadFile({
        url: '/export/factor/data',
        method: 'post',
        data: data,
        loading: true,
        loadingMsg: '正在准备导出，请稍后··· ···',
    });
}

/**
 * 导出计算因子 sql格式
 */
export function exportFactorToSql(data) {
    return downLoadFile({
        url: '/original/factor/export',
        method: 'post',
        data: data,
        loading: true,
        loadingMsg: '正在准备导出，请稍后··· ···',
    });
}

/**
 * 批量获取数据源
 */
export function getDataSourceByCodes(codeType, codes): Promise<any> {
    return Axios.post('/original/list/dataSource/codes?codeType=' + codeType, codes);
}

/**
 * 更新数据源
 */
export function updateDatasourceByCodes(data) {
    return Axios.post('/original/update/dataSource/codes', data);
}

/**
 * 获取计算因子详情
 */
export function getFactorDetail(factorCode): Promise<any> {
    return Axios.get('/original/factor/detail/' + factorCode);
}

/**
 * 验证前台的展示SQL的正确性
 */
export function verifyShowSql(data): Promise<any> {
    return Axios.post('/original/verify/showSql', data);
}

/**
 * 验证内存表是否有配置
 */
export function chekTableMemory(data): Promise<any> {
    return Axios.post('/original/verify/chekTableMemory', data);
}

/**
 * 验证计算字段是否存在存储过程里面
 */
export function queryProdField(data): Promise<any> {
    return Axios.post('/original/verify/queryProdField', data);
}

/**
 *查询计算因子中范围是否有用
 */
export function checkTableField(data): Promise<any> {
    return Axios.post('/original/verify/checkTableField', data);
}

/**
 * 生成表字段说明
 */
export function generateTableColumnNames(data): Promise<any> {
    return Axios.post('/original/resoleKey/generateTableColumnNames', data);
}

/**
 * 修改计算因子
 */
export function updateFactor(data): Promise<any> {
    return Axios.post('/original/factor/update', data);
}

/**
 * 添加计算因子
 */
export function addFactor(data): Promise<any> {
    return Axios.post('/original/factor/insert', data);
}

/* ***********  指标维护  *********** */

/**
 * 左侧树点击查询
 * @param code
 */
export function getOriginalBoundByPs(code: string): Promise<any> {
    return Axios.get('/original/listByps/' + code);
}

/**
 * 删除范围指标
 */
export function deleteOriginalBound(data): Promise<any> {
    return Axios.post('/original/delete/bound', data);
}

/**
 * 范围指标导出pdf
 */
export function exportOriginalBoundToPDF(data) {
    return downLoadFile({
        url: '/original/export/bound/pdf',
        method: 'post',
        data: data,
        loading: true,
        loadingMsg: '正在准备导出，请稍后··· ···',
    });
}

/**
 * 范围指标导出json
 */
export function exportOriginalBoundToJson(data) {
    return downLoadFile({
        url: '/export/bound/data',
        method: 'post',
        data: data,
        loading: true,
        loadingMsg: '正在准备导出，请稍后··· ···',
    });
}

/**
 * 范围指标导出sql
 */
export function exportOriginalBoundToSql(data) {
    return downLoadFile({
        url: '/original/export/bound',
        method: 'post',
        data: data,
        loadingMsg: '正在准备导出，请稍后··· ···',
    });
}

/**
 * 禁用或启用范围指标
 */
export function enableOrForbidOriginalBound(data): Promise<any> {
    return Axios.post('/original/update/boundVaild', data);
}

/**
 * 获取范围指标详情
 */
export function getOriginalBoundDetail(boundCode): Promise<any> {
    return Axios.get('/original/detail/' + boundCode);
}

/**
 * 生成 ResolveKey
 */
export function generateResolveKey(data): Promise<any> {
    return Axios.post('/original/resoleKey/generator', data);
}

/**
 * 新增范围指标
 */
export function addOriginalBound(data): Promise<any> {
    return Axios.post('/original/insert/bound', data);
}

/**
 * 修改范围指标
 */
export function updateOriginalBound(data): Promise<any> {
    return Axios.post('/original/update/bound', data);
}
